package com.csc.finalproject.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.csc.finalproject.domain.AccountInfo;
import com.csc.finalproject.service.AccountInfoService;

@Controller
public class AccountInfoController {
	@Autowired
	private AccountInfoService accountService;

	@RequestMapping(value = "/getAccountInfoForSupport")
	public String getAccountInfoForSupport(HttpServletRequest request) {
		String nav = "";
		List<AccountInfo> listAccount = accountService.getAccountInfos();
		request.setAttribute("listAccountInfo", listAccount);
		for (AccountInfo accountInfo : listAccount) {
			System.out.println(accountInfo.getAccountId());
		}
		nav = "support";
		
		return nav;
	}

	@RequestMapping(value = "/getAccountInfoForAdmin")
	public String getAccountInfoForAdmin(HttpServletRequest request) {
		String nav = "";
		List<AccountInfo> listAccount = accountService.getAccountInfos();
		request.setAttribute("listAccountInfo", listAccount);
		for (AccountInfo accountInfo : listAccount) {
			System.out.println(accountInfo.getAccountId());
		}
		nav = "admin";
		return nav;
	}
	@RequestMapping(value="/updateAccountInfo",method=RequestMethod.GET)
	public String updateAccountInfo(HttpServletRequest request)
	{
		String accountId = request.getParameter("accountIdEdit");
		String accountNumber = request.getParameter("accountNumberEdit");
		String identityCard = request.getParameter("identityCardEdit");
		String firstName = request.getParameter("firstNameEdit");
		String midName = request.getParameter("midNameEdit");
		String lastName = request.getParameter("lastNameEdit");
		String phone1 = request.getParameter("phone1Edit");
		String phone2 = request.getParameter("phone2Edit");
		String email1 = request.getParameter("email1Edit");
		String email2 = request.getParameter("email2Edit");
		String stateId = request.getParameter("stateEdit");
		accountService.editAccountInfo(Integer.parseInt(accountId), accountNumber, identityCard, firstName, lastName, midName, phone1, phone2, email1, email2,Integer.parseInt(stateId));
		return "forward:/getAccountInfoForSupport.html";
	}
}
